package com.ruoyi.common.utils;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;
import com.ruoyi.common.core.redis.RedisCache;
import org.apache.commons.compress.utils.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;

import static com.alibaba.fastjson2.JSON.toJSON;

/**
 * @Author: azh
 * Created on 2025-3-2 15:30
 */
public class AliSmsRemote {

    private static final Logger logger = LoggerFactory.getLogger(AliSmsRemote.class);

    private static Client createClient() throws Exception {
        Config config = new Config()
                .setAccessKeyId("")
                .setAccessKeySecret("");
        config.endpoint = "";
        return new Client(config);
    }



    public static void sms( String phone, String code) throws Exception {
        List<String> list = Lists.newArrayList();
        Client client = createClient();
        Map<String, String> map = new HashMap<>();
        map.put("code", code);
        SendSmsRequest request = new SendSmsRequest()
                .setPhoneNumbers(phone)
                .setSignName("name")
                .setTemplateParam("");

        try {
            client.sendSmsWithOptions(request, new RuntimeOptions());
        } catch (Exception e) {
            logger.error("sendSms error. phone: {}, code: {}", phone, code, e);
        }
    }

    public static void main(String[] args) throws Exception {
        sms( "18212694868", "123");
    }
}
